package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.aid.AidWarehouse;
import com.ruoyi.system.service.aid.IAidWarehouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库管理Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/aid/warehouse")
public class AidWarehouseController extends BaseController {
    @Autowired
    private IAidWarehouseService warehouseService;

    /**
     * 查询仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('aid:warehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(AidWarehouse warehouse) {
        startPage();
        List<AidWarehouse> list = warehouseService.selectWarehouseList(warehouse);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('aid:warehouse:export')")
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AidWarehouse warehouse) {
        List<AidWarehouse> list = warehouseService.selectWarehouseList(warehouse);
        ExcelUtil<AidWarehouse> util = new ExcelUtil<AidWarehouse>(AidWarehouse.class);
        return util.exportExcel(list, "仓库管理数据");
    }

    /**
     * 获取仓库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('aid:warehouse:query')")
    @GetMapping(value = "/{warehouseId}")
    public AjaxResult getInfo(@PathVariable("warehouseId") Long warehouseId) {
        return success(warehouseService.selectWarehouseById(warehouseId));
    }

    /**
     * 新增仓库管理
     */
    @PreAuthorize("@ss.hasPermi('aid:warehouse:add')")
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AidWarehouse warehouse) {
        return toAjax(warehouseService.insertWarehouse(warehouse));
    }

    /**
     * 修改仓库管理
     */
    @PreAuthorize("@ss.hasPermi('aid:warehouse:edit')")
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AidWarehouse warehouse) {
        return toAjax(warehouseService.updateWarehouse(warehouse));
    }

    /**
     * 删除仓库管理
     */
    @PreAuthorize("@ss.hasPermi('aid:warehouse:remove')")
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseIds}")
    public AjaxResult remove(@PathVariable Long[] warehouseIds) {
        return toAjax(warehouseService.deleteWarehouseByIds(warehouseIds));
    }

    /**
     * 获取所有仓库列表
     */
    @GetMapping("/all")
    public AjaxResult listAll() {
        List<AidWarehouse> list = warehouseService.selectWarehouseAll();
        return success(list);
    }
} 